﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MergeTool.ClassLib;
using MergeTool.ClassLib.Common;
using MergeTool.ClassLib.Configuration;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.VersionControl.Common;

namespace MergeTool
{
    class Program
    {
        static void Main(string[] args)
        {

            /*config handling testing
             * var test = new SettingsHelper();
            var test2 = test.Load();
            test.Save();
            test.Load();*/

            //Console.WriteLine(string.Join(",",Enum.GetNames(typeof(MergeOptionsEx))));

            Settings mySettings = Settings.GetInstance();
            TfsConnection myConnection = TfsConnection.GetInstance();
            /*
            var testResult = con.GeTfsConfigurationServer();
            var newTestResult = con.GeTfsTeamProjectCollection();
            var anotherTestResult =  con.GetVersionControlServer();
            var TeamProjectResult = con.GetTeamProject();

            ItemIdentifier ii = new ItemIdentifier(TeamProjectResult.ServerItem);

            BranchObject[] branches = TeamProjectResult.VersionControlServer.QueryRootBranchObjects(RecursionType.Full);

            var aaa = branches.Where(x => x.Properties.RootItem.IsDeleted);

            var validBranches = from br in branches where !br.Properties.RootItem.IsDeleted select br;
            */
            var neco = myConnection.GetVersionControlServer();
            BranchManager branch = new BranchManager();
            MergeManager mergeManager = new MergeManager();
            branch.GetAllNonDeletedBranchObjects();
            //branch.GetBaselessMergeBranches();
            //branch.GetUnavailableBranchNames();
            //branch.GetNonUniqueBranches();
            //branch.GetBaselessMergeBranches();
            var mergePaths = branch.GetFullBranchPathForMergeApproach(mySettings.MergeApproaches[0].Name);
            var mergeCandidates = mergeManager.GetMergeCandidates(mergePaths[0].BranchName, mergePaths[1].BranchName);
            //mergeManager.MergeByBranch(mergePaths[0].BranchName, mergePaths[1].BranchName, mergePaths[0].MergeOption);
            mergeManager.MergeByChangeset(mergePaths[0].BranchName, mergePaths[1].BranchName, mergeCandidates[0].Changeset, MergeOptionsEx.None);
            Console.ReadLine();
        }
    }
}
